package com.weixing.mall.provider.controller.front;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.AuthUtil;
import com.weixing.mall.core.support.auth.MemAuth;
import com.weixing.mall.provider.model.domain.Feedback;
import com.weixing.mall.provider.model.dto.FeedbackDto;
import com.weixing.mall.provider.model.vo.FeedbackTypeVo;
import com.weixing.mall.provider.service.IFeedbackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 意见反馈Api
 *
 * @author  wx
 * @date  2019/11/22 10:08
 * @since  1.0
 */
@RestController
@RequestMapping("front/feedback")
public class FrontFeedbackController extends BaseController {

    @Autowired
    private IFeedbackService feedbackService;

    /**
     * 新增意见反馈
     *
     * @param feedbackDto 参数
     * @return 结果
     */
    @PostMapping("save")
    public Result save(
                       @Validated @RequestBody FeedbackDto feedbackDto) {
        MemAuth memAuth = AuthUtil.getMemberExt();
        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(feedbackDto, feedback);
        feedback.setMemberId(memAuth.getMid());
        feedbackService.save(feedback);
        return ResultUtil.success();
    }

    /**
     * 反馈类别
     *
     * @return 类别
     */
    @GetMapping("typeList")
    public Result<List<FeedbackTypeVo>> getFeedBackType() {
        return ResultUtil.success(feedbackService.getFeedBackType());
    }

}
